package classes;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.Connection;

public class Connect {
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	static final String DB_URL = "jdbc:mysql://localhost/quranhadith";

	// Database credentials
	static final String USER = "root";
	static final String PASS = "junaid123.";
	static final String unicode = "?useUnicode=yes&characterEncoding=UTF-8";

	public Connection getConnection() {
		Connection conn = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");

			conn = (Connection) DriverManager.getConnection(DB_URL + unicode,
					USER, PASS);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return conn;
	}

	public ResultSet execute(Connection obj, String query) {
		try {
			Statement st = obj.createStatement();
			ResultSet rs = st.executeQuery(query);
			return rs;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void execute(Connection obj, String query, boolean flag) {
		try {
			Statement st = obj.createStatement();
			System.out.println(query);
			st.execute(query);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}